<template>
	<view class="conter1">
		<header-box :title="title"></header-box>
		<view class="wh100 h120 flex align-center justify-center">
			<view class="w100 h1" style="border-bottom: 1rpx solid #EEEEEE;">
			</view>
			<view class="" style="margin: 0 20rpx;">
				共 {{textList.length}} 个
			</view>
			<view class="w100 h1 bor-top" style="border-bottom: 1rpx solid #EEEEEE;">
			</view>
		</view>
		<!-- <view class="text-tab">
			<view class="box">
				<view class="marige-bor" v-for="(item, index) in textList" :key="index">
					<view class="diso-flex">
						<view class="">
							{{item.name}}
						</view>
						<view class="conter-image" @tap="skip(item)">
							<u-radio-group v-model="value" @change="radioGroupChange">
								<u-radio :name="item.id" active-color="#C0C2F9">
								</u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>
			</view>
		</view> -->
		
		<view class="text-tab padding-left padding-right u-border-bottom" v-for="(item,index) in textList" :key="index">
			<view class="flex align-center justify-between h100" @tap="skip(item)">
				<view class="">
					<text class="cuIcon-home"></text>
					<text class="" style="padding: 0 10rpx;">{{item.store_name}}</text>
					<text class="cuIcon-right"></text>
				</view>
				<view class="">
					最近盘点：{{item.createtime}}
				</view>
			</view>
			<!-- <view class="flex align-center justify-between">
				<view class="">
					最近盘点：{{item.createtime}}
				</view>
				<view class="bgc1" @tap="propShow(item)">
					<text class="cuIcon-writefill"></text>
				</view>
			</view> -->
			<view class="flex justify-between h100 align-center" style="font-family: PingFang SC;" >
				<view class="">
					商品总数：{{item.sum}} 件
				</view>
				<view class="bgc">
					共 {{item.count}} 类
				</view>
			</view>
		</view>


		<!-- <navigator url="#" @click="showRemove1 = true" class="add">
			<image src="../../static/index/add.png" mode=""></image>
		</navigator> -->

		

		<!-- 编辑 弹出框 -->
		<u-popup v-model="showRemove" mode="center" width="580rpx" height="170px" border-radius="10">
			<view class="tilte-text">更改 - {{stockName}}</view>
			<view class="" style="font-size: 28rpx; 
				color: #999999; 
				width: 480rpx;
				height: 70rpx; 
				background: #F5F5F5; 
				margin: 0 auto;
				border-radius: 20rpx;">
				<input type="text" style="background: #F5F5F5;
					width: 480rpx; height: 100%;
					padding-left: 10rpx;
					text-align: center;
					border-radius: 10rpx;"
				 v-model="val" placeholder="请输入仓库名" />
			</view>
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove= false">取消</text>
				<text @click="removeText">确定</text>
			</view>
		</u-popup>


		<u-popup v-model="showRemove1" mode="center" width="580rpx" height="170px" border-radius="10">
			<view class="tilte-text">添加仓库</view>
			<view class="" style="font-size: 28rpx; 
				color: #999999; 
				width: 480rpx;
				height: 70rpx; 
				background: #F5F5F5; 
				margin: 0 auto;
				border-radius: 20rpx;">
				<input type="text" style="background: #F5F5F5;
					width: 480rpx; height: 100%;
					padding-left: 10rpx;
					text-align: center;
					border-radius: 10rpx;"
				 v-model="valName" placeholder="请输入仓库名" />
			</view>
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove1 = false">取消</text>
				<text @click="addNmame">确定</text>
			</view>
		</u-popup>



		<u-popup v-model="showRemove2" mode="center" width="580rpx" height="130px" border-radius="10">
			<view class="tilte-text">删除 - {{stockName}}</view>
		
			<view class="btn-bor">
				<text class="left-bor" @click="showRemove2 = false">取消</text>
				<text @click="removeSrock">确定</text>
			</view>
		</u-popup>



	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				title: '仓库',
				textList: [],
				redactShow: false,
				list: [{
					name: '编辑',
					show: true,
					url: ''
				},
				{
					name: '查看',
					show: true,
					url: ''
				},
				// {
				// 	name: '删除',
				// 	show: true
				// },
				{
					name: '取消',
					show: false
				}],
				showRemove: false,
				showRemove1: false,
				showRemove2: false,
				tabText: 0,
				total: 0,
				val: '',
				valName: '',
				stockName: '',
				stocId: '',
				value: 0,
				page: 1,
			}
		},
		onLoad() {
			this.stockList()
		},
		onShow() {},
		onReachBottom() {
			if(this.total < 10) return this.$tools.msg('没有更多了！')
			this.page++
			this.stockList()
		},
		methods: {

			radioGroupChange(e) {
				// console.log(e);
			},

			// 获取列表
			async stockList() {
				const res = await this.$u.post("/api/Invoic/store_find",{
					page: this.page,
					pagesize: 10,
				});
				this.textList = res.data
				this.value = res.data[0].id
				// this.total = res.data.length
			},

			// 修改仓库名
			async removeText() {
				console.log('修改仓库名', this.val)
				if (!this.val) return this.$tools.msg('仓库名不能未空')
				const res = await this.$u.post("api/jinxiao.Store/edit?id=" + this.stocId + "&name=" + this.val, {});

				this.$tools.msg("修改成功");
				this.showRemove = false
				this.redactShow = false
				this.val = ''
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("修改失败");
				}
			},

			// 添加仓库
			async addNmame() {
				if (!this.valName) return this.$tools.msg('名字不能为空')
				const res = await this.$u.post("api/jinxiao.Store/add", {
					name: this.valName
				});
				this.$tools.msg("添加成功");
				this.showRemove1 = false
				this.redactShow = false
				this.valName = ''
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("添加失败");
				}
			},

			// 删除仓库
			async removeSrock() {
				if (!this.stocId) return this.$tools.msg('请选择需要删除的仓库')
				const res = await this.$u.post("api/jinxiao.Store/delete?id=" + this.stocId, {});
				this.$tools.msg("删除成功");
				this.showRemove2 = false
				this.redactShow = false
				this.stockList()
				if (res.code !== 1) {
					this.$tools.msg("删除失败");
				}
			},

			skip(item) {
				console.log('跳转的路000劲', item.name)
				this.stockName = item.store_name
				this.stocId = item.id
				
				// 跳转仓库详情
				uni.navigateTo({
					url: '/pages/warehouse/warehouseInfo?id=' + this.stocId + "&name=" + this.stockName
				})
				
			},
			
			propShow(item) {
				this.stockName = item.store_name
				this.showRemove = true
			},

			elect(item, index) {
				
				this.tabText = index
				this.redactShow = item.show
				
				if (index == 0) {
					// 跳转到编辑页面
					this.showRemove = true
				} else if (index == 1) {
					// this.showRemove2 = true
					// 跳转仓库详情
					uni.navigateTo({
						url: '/pages/warehouse/warehouseInfo?id=' + this.stocId + "&name=" + this.stockName
					})
					
					this.redactShow = false
				} else if (index == 2) {
					// 调用删除事件
					
					// this.showRemove2 = true
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.conter1 {
		width: 100%;
		height: 100%;
		position: relative;
		background-color: #F7F7F7;

		image {
			width: 100%;
			height: 100%;
		}

		.text-tab {
			width: 100%;
			padding-bottom: 0;
			margin-bottom: 20rpx;
			font-family: PingFang SC;
			background-color: #FFFFFF !important;
			
			.bgc {
				width: 146rpx;
				height: 46rpx;
				line-height: 46rpx;
				color: #7578EF;
				text-align: center;
				border-radius: 6rpx;
				background: RGBA(227, 228, 252, 0.2);
			}
			
			.bgc1 {
				width: 146rpx;
				height: 46rpx;
				line-height: 46rpx;
				color: #7578EF;
				text-align: center;
				border-radius: 6rpx;
			}
		}


		// 加号
		.add {
			position: fixed;
			bottom: 200rpx;
			right: 40rpx;
			width: 100rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			border-radius: 50%;
			font-size: 100rpx;
		}

		.total {
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			height: 100rpx;
			padding: 0 60rpx 0 30rpx;
			background-color: #FFFFFF;
		}


		.padd-text {
			width: 80%;
			height: 106rpx;
			line-height: 106rpx;
			text-align: center;
			font-size: 28rpx;
			color: #333;
			border-bottom: 1rpx solid #EEEEEE;
			margin: 0 auto;
		}

		.color-text {
			color: #7278EC;
		}

		.none-color {
			color: #000;
		}

		.padd-text:last-child {
			border-bottom: 0;
		}



		.tilte-text {
			color: #333;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			font-size: 32rpx;
		}

		.btn-bor {
			width: 90%;
			height: 113rpx;
			color: #7278EC;
			margin: 0 auto;
			line-height: 113rpx;
			margin-top: 40rpx;
			display: flex;
			justify-content: space-around;
			border-top: 1rpx solid #EEEEEE;

			.left-bor {
				border-right: 1rpx solid #EEEEEE;
			}

			text {
				display: inline-block;
				width: 40%;
				height: 113rpx;
				text-align: center;
			}
		}
	}
</style>
